/**
 * 
 */
package STUDENTS.PHAMHONGSON.MVC.Eg07142016.Models;

import java.text.DecimalFormat;

import STUDENTS.PHAMHONGSON.MVC.Eg07142016.Objects.MathEquation;

/**
 * @author WindChime
 *
 */
public class MathEquationResolverModel {

	public String ResolverQuadraticEquation(MathEquation obj )
	{
		double deltaTemp = 0.00;
		String outPut = "";
		DecimalFormat precision = new DecimalFormat("0.000");
		
		if (obj.getdNumbA()==0 && obj.getdNumbC()==0)
			{
			obj.setRootEquation2(0);
			obj.setRootEquation1(0);
			outPut +="This quadratic equation have only 1 root: " + obj.getRootEquation1();
			}
		else if (obj.getdNumbA()==0)
		{
			obj.setRootEquation1(- obj.getdNumbC()/obj.getdNumbB());
			obj.setRootEquation2(- obj.getdNumbC()/obj.getdNumbB());
			outPut +="This quadratic equation have only 1 root: " + precision.format(obj.getRootEquation1());
		}
		else if (obj.getdNumbC()==0)
		{
			obj.setRootEquation1(0);
			obj.setRootEquation2( - obj.getdNumbB()/ obj.getdNumbA());
			outPut += "The first root is: " + obj.getRootEquation1();
			outPut += "\nThe second root is: " + precision.format(obj.getRootEquation2());
		}
		else 
		{
			deltaTemp = obj.getdNumbB()*obj.getdNumbB() - 4* obj.getdNumbA()* obj.getdNumbC();
			if (deltaTemp < 0) outPut += "Sory, dont have any root for your quadratic equation."; 
			else 
				{
				obj.setRootEquation1((- obj.getdNumbB() + deltaTemp ) / 2 / obj.getdNumbC());
				obj.setRootEquation2((- obj.getdNumbB() - deltaTemp)/ 2 / obj.getdNumbC());
				outPut += "The first root is: " + precision.format(obj.getRootEquation1());
				outPut += "\nThe second root is: " + precision.format(obj.getRootEquation2());
				}
		}		
		return outPut;
	}
}
